package com.joinlabs.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import com.joinlabs.entity.Wares;
import com.joinlabs.mapper.WaresMapper;
import com.joinlabs.service.IProductSystemer;
@Service("WaresGroService")
public class ProductSystemer implements IProductSystemer {

	@Resource
	private WaresMapper waresMapper;
	@Override
	public List<Wares> findInfobyGrounding(int waresGrounding) {
		List<Wares> waress = waresMapper.findInfobyGrounding(new BigDecimal(waresGrounding));
		//System.out.println("---------------------"+waress.size());
		return waress;
	}
	
	public List<Wares> findInfoAll(){
		List<Wares> waress = waresMapper.findInfoAll();
		
		
		return waress;
	}
//批量删除pid
	@Override
	public void delProsbyPids(String[] strs) {
		for (String s : strs) {
			BigDecimal pid = new BigDecimal(s);
			waresMapper.deleteByPrimaryKey(pid);
		}
	}
//模糊查询商品
	@Override
	public List<Wares> selectInfobywaresName(String waresName) {
		String likeName = "%"+waresName+"%";
		List<Wares> waress = waresMapper.selectBylikeName(likeName);
		return waress;
	}
//批量上下架
	@Override
	public void updateProsbyPids(String[] strs , int a) {
		// TODO Auto-generated method stub
		if(a == 0) {
		for (String s : strs) {
			BigDecimal pid = new BigDecimal(s);
			waresMapper.updateSJbypids(pid);
		}
		}
		if(a == 1) {
			for (String s : strs) {
				BigDecimal pid = new BigDecimal(s);
				waresMapper.updateXJbypids(pid);
			}
			}
	}
//添加商品
	@Override
	public void insertProbyInfo(Wares wares) {
		// TODO Auto-generated method stub
		
		int a = 0;
		BigDecimal salesVolume = new BigDecimal(a);
		wares.setSalesVolume(salesVolume);
		long waresCount = 0;
		wares.setWaresCount(waresCount);
		Short waresGrounding = 0;
		wares.setWaresGrounding(waresGrounding);
		Short waresUser  = 1;
		wares.setWaresUser(waresUser);
		int b =  waresMapper.insertProbyInfo(wares);
	}
//根据pid查找数据
	
	@Override
	public Wares findInfobyPid(BigDecimal pid) {
		// TODO Auto-generated method stub
		Wares waers = waresMapper.findInfobyPid(pid);
		return waers;
	}

	@Override
	public void updateProCountbyPid(Wares wares) {
		// TODO Auto-generated method stub
		waresMapper.updateByPrimaryKeySelective(wares);
	}

//用户添加商品
		@Override
		public void insertuserProbyInfo(Wares wares) {
			// TODO Auto-generated method stub
			
			int a = 0;
			BigDecimal salesVolume = new BigDecimal(a);
			wares.setSalesVolume(salesVolume);
//			long waresCount = 0;
//			wares.setWaresCount(waresCount);
			Short waresGrounding = 0;
			wares.setWaresGrounding(waresGrounding);
			Short waresUser  = 2;
			wares.setWaresUser(waresUser);
			int b =  waresMapper.insertProbyInfo(wares);
		}

		@Override
		public List<Wares> findInfobywaresUser() {
			// TODO Auto-generated method stub
			List<Wares> waress = waresMapper.findInfobywaresUser();
			return waress;
		}

}
